#include "net_interface.h"

/*
int NetInterface::addFollow(string user, string follow){
    BSONObjBuilder      builder;
    BSONObj             sendobj;

    builder << REQUEST_TYPE<<CMD_UPDATE << REQUEST_COLL<<"test.follows" << 
        REQUEST_QUERY<<BSON("user"<<user)<< REQUEST_SERT<<true << 
        REQUEST_BODY << BSON("$addToSet"<< BSON("fol"<<follow));
    sendobj = builder.obj();
    cout<< "send command:"<<sendobj.jsonString()<<endl;
    return send(sockfd, (void*)sendobj.jsonString().c_str(), sendobj.jsonString().length(), 0);
}

int NetInterface::delFollow(string user, string follow){
    BSONObjBuilder      builder;
    BSONObj             sendobj;

    builder << REQUEST_TYPE<<CMD_UPDATE << REQUEST_COLL<<"test.follows" << 
        REQUEST_QUERY<<BSON("user"<<user)<< REQUEST_SERT<<true << 
        REQUEST_BODY << BSON("$pull"<< BSON("fol"<<follow));
    sendobj = builder.obj();
    cout<< "send command:"<<sendobj.jsonString()<<endl;
    return send(sockfd, (void*)sendobj.jsonString().c_str(), sendobj.jsonString().length(), 0);
}

BSONObj NetInterface::getFollows(string user){
    BSONObjBuilder      builder;
    char                buf[STREAM_BUF_SIZE];
    BSONObj             obj;

    builder<< REQUEST_TYPE<<CMD_QUERY << REQUEST_COLL<<"test.follows" <<
        REQUEST_QUERY <<BSON("user"<<user)<< REQUEST_EXTRA << BSON("fol"<<1);
    BSONObj sendobj = builder.obj();
    cout<< "send command:"<<sendobj.jsonString()<<endl;
    if(send(sockfd, (void*)sendobj.jsonString().c_str(), sendobj.jsonString().length(), 0) < 0){
        return obj;
    }
    if(recv(sockfd, buf, STREAM_BUF_SIZE, 0) < 0){
        return obj;
    }

    return fromjson(buf);
}

int NetInterface::addFan(string user, string follow){
    BSONObjBuilder      builder;
    BSONObj             sendobj;

    builder << REQUEST_TYPE<<CMD_UPDATE << REQUEST_COLL<<"test.fans" 
        << REQUEST_QUERY<<BSON("user"<<user)<< REQUEST_SERT<<true 
        << REQUEST_BODY << BSON("$addToSet"<< BSON("fol"<<follow));
    sendobj = builder.obj();
    cout<< "send command:"<<sendobj.jsonString()<<endl;
    return send(sockfd, (void*)sendobj.jsonString().c_str(), sendobj.jsonString().length(), 0);
}
*/
